<!DOCTYPE html>
<html>
<head>
<#include "../include/include.ftl"/>
<meta charset="utf-8">
<title>增加缴纳单位表单</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<script type="text/javascript">
	layui.use('form', function() {//初始化表单
		var form = layui.form;
		form.on('submit(add)', function(data) {//监听submit提交
			layerAjax('${basePath}/api/unit/save-unit/', data.field, 'unitList');
			return false;
		})
	});

	function inputOnBlur() {
		var nameValue = $("#name").val();
		var id = "1";
		$.ajax({
			url : "${basePath}/paymentUnit/validate-unit-name",
			type : 'post',
			data : {
				"name" : nameValue,
				"id" : id
			},
			traditional : true,
			success : function(d) {
				if (d.code == 12) {
					layer.msg('用户名已存在！', {
						icon : 5
					});
					$("input[name=name]").focus();
				}
			},
			error : function(e) {
				layer.alert("发生错误", {
					icon : 6
				}, function() {
					var index = parent.layer.getFrameIndex(window.name);
					parent.layer.close(index);
				});
			}
		});
		return false;
	}
</script>
</head>
<body>
	<form class="layui-form" style="margin-top: 50px">
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label"><span style="color: black;">单位名称:</span><span
					style="color: red;"> *</span></label>
				<div class="layui-input-inline">
					<input type="text" name="name" class="layui-input" id="name"
						lay-verify="required" onBlur="inputOnBlur()">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">单位类型:</label>

				<div class="layui-input-inline">
					<select name="type" lay-search>
						<option>请选择</option>
						<option value="1">学校</option>
						<option value="2">物业</option>
					</select>
				</div>
			</div>
		</div>

		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label"><span style="color: black;">对公账号:</span><span
					style="color: red;"> *</span></label>
				<div class="layui-input-inline">
					<input type="text" name=corporateAccount class="layui-input"
						lay-verify="required">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">负责人:</label>
				<div class="layui-input-inline">
					<input type="text" name="principal" class="layui-input">
				</div>
			</div>
		</div>

		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label"><span style="color: black;">联系电话:</span><span
					style="color: red;"> *</span></label>
				<div class="layui-input-inline">
					<input type="text" name=phoneNumber class="layui-input"
						lay-verify="required|phone">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">地址:</label>
				<div class="layui-input-inline">
					<input type="text" name="address" class="layui-input">
				</div>
			</div>
		</div>

		<div class="layui-form-item"
			style="float: right; margin-right: 40%; margin-top: 30px">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit="" lay-filter="add">添加单位</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>
</body>
</html>